#include "Comm.hpp"
#include "Fifo.hpp"

int main()
{
    key_t key = GetShmKeyOrDie();
    cout << "key: " << ToHex(key) << endl;

    int shmid = GetShm(key, defaultsize);
    cout << "shmid: " << shmid << endl;
    // sleep(2);

    char *addr = (char *)ShmAttach(shmid);

    cout << "Attach shm success, adde: " << ToHex((uint64_t)addr) << endl;
    // sleep(2);

    memset(addr, 0, defaultsize);

    Sync syn;
    syn.OpenWriteOrDie();

    // 可以通信了
    for (char c = 'A'; c <= 'Z'; c++)
    {
        addr[c - 'A'] = c;
        sleep(1);
        syn.Wakeup();
    }

    ShmDetach(addr);
    cout << "Detach shm success, adde: " << ToHex((uint64_t)addr) << endl;

    sleep(5);
    return 0;
}